package fragment.tabhostFragment;


import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.widget.TabHost;

import com.lanou.horo.myapplication.R;

import fragment.AbsBaseFragment;
import fragment.tabhostFragment.CustomPageFragment;
import fragment.tabhostFragment.DownloadPageFragment;
import fragment.tabhostFragment.FindPageFragment;
import fragment.tabhostFragment.MePageFragment;
import fragment.tabhostFragment.PlaybtnPageFragment;

/**
 * 主要fragment
 * Created by dllo on 15/11/16.
 */
public class MainFragment extends AbsBaseFragment {
    private TabHost tabHost;
    private FragmentManager manager;
    @Override
    protected int getLayoutView() {
        return R.layout.fragment_main;
    }

    @Override
    protected void initView() {
        tabHost = findView(android.R.id.tabhost);
    }

    @Override
    protected void initData() {
        initTabSpace();
        initFragment();
    }
    private void initTabSpace() {

        tabHost.setup();
        LayoutInflater inflater = LayoutInflater.from(getContext());

        tabHost.addTab(tabHost.newTabSpec("first").setContent(R.id.viewOne).
                setIndicator(inflater.inflate(R.layout.tab_find_tabhost, null)));

        tabHost.addTab(tabHost.newTabSpec("second").setContent(R.id.viewTwo).
                setIndicator(inflater.inflate(R.layout.tab_custom_tabhost, null)));

        tabHost.addTab(tabHost.newTabSpec("three").setContent(R.id.viewThree).
                setIndicator(inflater.inflate(R.layout.tab_playbtn_tabhost, null)));

        tabHost.addTab(tabHost.newTabSpec("four").setContent(R.id.viewFour).
                setIndicator(inflater.inflate(R.layout.tab_download_tabhost, null)));

        tabHost.addTab(tabHost.newTabSpec("five").setContent(R.id.viewFive).
                setIndicator(inflater.inflate(R.layout.tab_me_tabhost, null)));
    }

    public void initFragment() {
        manager = getFragmentManager();
        FragmentTransaction fragmentTransaction = manager.beginTransaction();
        fragmentTransaction.replace(R.id.viewOne, new FindPageFragment());
        fragmentTransaction.replace(R.id.viewTwo, new CustomPageFragment());
        fragmentTransaction.replace(R.id.viewThree, new PlaybtnPageFragment());
        fragmentTransaction.replace(R.id.viewFour, new DownloadPageFragment());
        fragmentTransaction.replace(R.id.viewFive, new MePageFragment());
        fragmentTransaction.commit();
    }

}
